home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Obuttn1a.cpp < prev    next >
C/C++ Source or Header  |  1999-01-29  |  4KB  |  121 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Obuttn1a.h"
  6.  
  7. TColor OColor[4] =
  8.   {clBlack, clGray, clSilver, clWhite};
  9.  
  10. //---------------------------------------------------------------------------
  11. static inline TOButton *ValidCtrCheck()
  12. {
  13.     return new TOButton(NULL);
  14. }
  15. //---------------------------------------------------------------------------
  16. __fastcall TOButton::TOButton(TComponent* Owner)
  17.     : TCustomControl(Owner)
  18. {
  19.   Color = clBtnFace;
  20.   SetSize (Rect (0, 0, 50, 50));
  21.   Pressed = false;
  22. }
  23. //---------------------------------------------------------------------------
  24. __fastcall TOButton::TOButton(TComponent* Owner, TColor Farbe)
  25.     : TCustomControl(Owner)
  26. {
  27.   Color = Farbe;
  28.   SetSize (Rect (0, 0, 50, 50));
  29.   Pressed = false;
  30. }
  31. //---------------------------------------------------------------------------
  32. __fastcall TOButton::TOButton(TComponent* Owner, TRect Rechteck)
  33.     : TCustomControl(Owner)
  34. {
  35.   Color = clBtnFace;
  36.   SetSize (Rechteck);
  37.   Pressed = false;
  38. }
  39. //---------------------------------------------------------------------------
  40. namespace Obuttn1a
  41. {
  42.     void __fastcall Register()
  43.     {
  44.         TComponentClass classes[1] = {__classid(TOButton)};
  45.         RegisterComponents("ZusΣtzlich", classes, 0);
  46.     }
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TOButton::SetSize (TRect Rechteck)
  50. {
  51.   Left   =  Rechteck.Left;
  52.   Top    =  Rechteck.Top;
  53.   Width  =  Rechteck.Right  - Rechteck.Left;
  54.   Height =  Rechteck.Bottom - Rechteck.Top;
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TOButton::SetColor(TColor OBrush, TColor OPen)
  58. {
  59.   Canvas->Brush->Color = OBrush;
  60.   Canvas->Pen->Color = OPen;
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TOButton::MouseDown
  64.   (TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
  65. {
  66.   TCustomControl::MouseDown (Button, Shift, X, Y);
  67.   if (Button == mbLeft)
  68.   {
  69.     Pressed = true;
  70.     Paint ();
  71.   }
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TOButton::MouseUp
  75.   (TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
  76. {
  77.   TCustomControl::MouseUp (Button, Shift, X, Y);
  78.   Pressed = false;
  79.   Paint ();
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TOButton::Paint (void)
  83. {
  84.   // Liniendicke
  85.   Canvas->Pen->Width = 2;
  86.  
  87.   // OButton gedrⁿckt
  88.   if (Pressed)
  89.   {
  90.     for (int i=1; i<5; i++)
  91.     {
  92.       SetColor (OColor[(i-1)/2], OColor[(i-1)/2]);
  93.       Canvas->Arc (i, i, Width-i, Height-i, i, i, i, i);
  94.     }
  95.   }
  96.   // OButton nicht gedrⁿckt
  97.   else
  98.   {
  99.     for (int i=1; i<5; i++)
  100.     {
  101.       SetColor (OColor[i-1], OColor[i-1]);
  102.       Canvas->Arc (i, i, Width-i, Height-i, i, i, i, i);
  103.     }
  104.     /* Zum Experimentieren:
  105.     for (int i=1; i<5; i++)
  106.     {
  107.       SetColor (Color, OColor[3]);
  108.       Canvas->Arc (i, i, Width-i, Height-i, Width-i, i, i, Height-i);
  109.       SetColor (Color, OColor[1]);
  110.       Canvas->Arc (i, i, Width-i, Height-i, i, Width-i, Height-i, i);
  111.     }
  112.     SetColor (Color, OColor[0]);
  113.     Canvas->Arc (1, 1, Width-1, Height-1, 1, 1, 1, 1);
  114.     */
  115.   }
  116.   // OButton-FlΣche
  117.   SetColor (Color, Color);
  118.   Canvas->Ellipse (5, 5, Width-5, Height-5);
  119. }
  120. //---------------------------------------------------------------------------
  121.